using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

using System.Text;

namespace CS6238Project2.Banking.Communication
{
    /// <summary>
    /// A cryptographic key which, when inserted into a certificate, allows the
    /// encryption and decryption of data.
    /// </summary>
    [XmlRootAttribute(IsNullable = true)]
    [Serializable]
    public class Token
    {
        RijndaelManaged aes;
        ICryptoTransform decrypt;
        ICryptoTransform encrypt;
        private byte[] key;
        private byte[] iv;


        public Token()
        {
            aes = new RijndaelManaged();
            aes.KeySize = 256;
            aes.GenerateKey();
            key = aes.Key;
            aes.GenerateIV();
            iv = aes.IV;
            decrypt = aes.CreateDecryptor();
            encrypt = aes.CreateEncryptor();
            
        }

        public Token(byte [] Key, byte [] IV)
        {
            this.aes = new RijndaelManaged();
            this.aes.KeySize = 256;
            this.key = Key;
            this.aes.Key = key;
            this.iv = IV;
            this.aes.IV = iv;
            this.decrypt = aes.CreateDecryptor();
            this.encrypt = aes.CreateEncryptor();
        }


        [XmlIgnore]
        public RijndaelManaged AES
        {
            get { return aes; }
            set { aes = value; }
        }
        [XmlIgnore]
        public ICryptoTransform Encryptor
        {
            get { return encrypt; }
            set { encrypt = value; }
        }
        [XmlIgnore]
        public ICryptoTransform Decryptor
        {
            get { return decrypt; }
            set { decrypt = value; }
        }

        /// <summary>
        /// The IV of the token
        /// </summary>
        public byte[] IV
        {
            get { return iv; }
            set { iv = value; }
        }

        /// <summary>
        /// The 256 bit key of the Token
        /// </summary>
        public byte[] Key
        {
            get { return key; }
            set { key = value; }
        }
        

    }
}
